/*
 * Copyright (c) 2017. Visionet and/or its affiliates. All right reserved.
 * VISIONET PROPRIETARY/CONFIDENTIAL.
 */
package com.visionet.jumper.core.support.spring;

import com.visionet.jumper.core.support.spring.BeanCopier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author TC.Ubuntu
 * @since 2017/7/11.
 */
public abstract class DomainTransfer<T> {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	public void from(T obj){
			BeanCopier.getInstance().copyBean(obj, this);
		}

	public T to(Class<T> clazz){
		try {
			T instance = clazz.newInstance();
			BeanCopier.getInstance().copyBean(this, instance);
			return instance;
		} catch (Exception e) {
			logger.error("Transfer DTO to entity due to error",e);
			return null;
		}
	}
}
